home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / kuaqe.zip / PLATS.QC < prev    next >
Text File  |  1996-07-25  |  8KB  |  365 lines

  1.  
  2.  
  3. void() plat_center_touch;
  4. void() plat_outside_touch;
  5. void() plat_trigger_use;
  6. void() plat_go_up;
  7. void() plat_go_down;
  8. void() plat_crush;
  9. float PLAT_LOW_TRIGGER = 1;
  10.  
  11. void() plat_spawn_inside_trigger =
  12. {
  13.     local entity    trigger;
  14.     local vector    tmin, tmax;
  15.  
  16. //
  17. // middle trigger
  18. //    
  19.     trigger = spawn();
  20.     trigger.touch = plat_center_touch;
  21.     trigger.movetype = MOVETYPE_NONE;
  22.     trigger.solid = SOLID_TRIGGER;
  23.     trigger.enemy = self;
  24.     
  25.     tmin = self.mins + '25 25 0';
  26.     tmax = self.maxs - '25 25 -8';
  27.     tmin_z = tmax_z - (self.pos1_z - self.pos2_z + 8);
  28.     if (self.spawnflags & PLAT_LOW_TRIGGER)
  29.         tmax_z = tmin_z + 8;
  30.     
  31.     if (self.size_x <= 50)
  32.     {
  33.         tmin_x = (self.mins_x + self.maxs_x) / 2;
  34.         tmax_x = tmin_x + 1;
  35.     }
  36.     if (self.size_y <= 50)
  37.     {
  38.         tmin_y = (self.mins_y + self.maxs_y) / 2;
  39.         tmax_y = tmin_y + 1;
  40.     }
  41.     
  42.     setsize (trigger, tmin, tmax);
  43. };
  44.  
  45. void() plat_hit_top =
  46. {
  47.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  48.     self.state = STATE_TOP;
  49.     self.think = plat_go_down;
  50.     self.nextthink = self.ltime + 3;
  51. };
  52.  
  53. void() plat_hit_bottom =
  54. {
  55.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  56.     self.state = STATE_BOTTOM;
  57. };
  58.  
  59. void() plat_go_down =
  60. {
  61.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  62.     self.state = STATE_DOWN;
  63.     SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
  64. };
  65.  
  66. void() plat_go_up =
  67. {
  68.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  69.     self.state = STATE_UP;
  70.     SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
  71. };
  72.  
  73. void() plat_center_touch =
  74. {
  75.     if (other.classname != "player")
  76.         return;
  77.         
  78.     if (other.health <= 0)
  79.         return;
  80.  
  81.     self = self.enemy;
  82.     if (self.state == STATE_BOTTOM)
  83.         plat_go_up ();
  84.     else if (self.state == STATE_TOP)
  85.         self.nextthink = self.ltime + 1;    // delay going down
  86. };
  87.  
  88. void() plat_outside_touch =
  89. {
  90.     if (other.classname != "player")
  91.         return;
  92.  
  93.     if (other.health <= 0)
  94.         return;
  95.         
  96. //dprint ("plat_outside_touch\n");
  97.     self = self.enemy;
  98.     if (self.state == STATE_TOP)
  99.         plat_go_down ();
  100. };
  101.  
  102. void() plat_trigger_use =
  103. {
  104.     if (self.think)
  105.         return;        // allready activated
  106.     plat_go_down();
  107. };
  108.  
  109.  
  110. void() plat_crush =
  111. {
  112. //dprint ("plat_crush\n");
  113.  
  114.     T_Damage (other, self, self, 1);
  115.     
  116.     if (self.state == STATE_UP)
  117.         plat_go_down ();
  118.     else if (self.state == STATE_DOWN)
  119.         plat_go_up ();
  120.     else
  121.         objerror ("plat_crush: bad self.state\n");
  122. };
  123.  
  124. void() plat_use =
  125. {
  126.     self.use = SUB_Null;
  127.     if (self.state != STATE_UP)
  128.         objerror ("plat_use: not in up state");
  129.     plat_go_down();
  130. };
  131.  
  132.  
  133. /*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER
  134. speed    default 150
  135.  
  136. Plats are always drawn in the extended position, so they will light correctly.
  137.  
  138. If the plat is the target of another trigger or button, it will start out disabled in the extended position until it is trigger, when it will lower and become a normal plat.
  139.  
  140. If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determined by the model's height.
  141. Set "sounds" to one of the following:
  142. 1) base fast
  143. 2) chain slow
  144. */
  145.  
  146.  
  147. void() func_plat =
  148.  
  149. {
  150. local entity t;
  151.  
  152.     if (!self.t_length)
  153.         self.t_length = 80;
  154.     if (!self.t_width)
  155.         self.t_width = 10;
  156.  
  157.     if (self.sounds == 0)
  158.         self.sounds = 2;
  159. // FIX THIS TO LOAD A GENERIC PLAT SOUND
  160.  
  161.     if (self.sounds == 1)
  162.     {
  163.         precache_sound ("plats/plat1.wav");
  164.         precache_sound ("plats/plat2.wav");
  165.         self.noise = "plats/plat1.wav";
  166.         self.noise1 = "plats/plat2.wav";
  167.     }
  168.  
  169.     if (self.sounds == 2)
  170.     {
  171.         precache_sound ("plats/medplat1.wav");
  172.         precache_sound ("plats/medplat2.wav");
  173.         self.noise = "plats/medplat1.wav";
  174.         self.noise1 = "plats/medplat2.wav";
  175.     }
  176.  
  177.  
  178.     self.mangle = self.angles;
  179.     self.angles = '0 0 0';
  180.  
  181.     self.classname = "plat";
  182.     self.solid = SOLID_BSP;
  183.     self.movetype = MOVETYPE_PUSH;
  184.     setorigin (self, self.origin);    
  185.     setmodel (self, self.model);
  186.     setsize (self, self.mins , self.maxs);
  187.  
  188.     self.blocked = plat_crush;
  189.     if (!self.speed)
  190.         self.speed = 150;
  191.  
  192. // pos1 is the top position, pos2 is the bottom
  193.     self.pos1 = self.origin;
  194.     self.pos2 = self.origin;
  195.     if (self.height)
  196.         self.pos2_z = self.origin_z - self.height;
  197.     else
  198.         self.pos2_z = self.origin_z - self.size_z + 8;
  199.  
  200.     self.use = plat_trigger_use;
  201.  
  202.     plat_spawn_inside_trigger ();    // the "start moving" trigger    
  203.  
  204.     if (self.targetname)
  205.     {
  206.         self.state = STATE_UP;
  207.         self.use = plat_use;
  208.     }
  209.     else
  210.     {
  211.         setorigin (self, self.pos2);
  212.         self.state = STATE_BOTTOM;
  213.     }
  214. };
  215.  
  216. //============================================================================
  217.  
  218. void() train_next;
  219. void() func_train_find;
  220.  
  221. void() train_blocked =
  222. {
  223.     if (time < self.attack_finished)
  224.         return;
  225.     self.attack_finished = time + 0.5;
  226.     T_Damage (other, self, self, self.dmg);
  227. };
  228. void() train_use =
  229. {
  230.     if (self.think != func_train_find)
  231.         return;        // already activated
  232.     train_next();
  233. };
  234.  
  235. void() train_wait =
  236. {
  237.     if (self.wait)
  238.     {
  239.         self.nextthink = self.ltime + self.wait;
  240.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  241.     }
  242.     else
  243.         self.nextthink = self.ltime + 0.1;
  244.     
  245.     self.think = train_next;
  246. };
  247.  
  248. void() train_next =
  249. {
  250.     local entity    targ;
  251.  
  252.     targ = find (world, targetname, self.target);
  253.     self.target = targ.target;
  254.     if (!self.target)
  255.         objerror ("train_next: no next target");
  256.     if (targ.wait)
  257.         self.wait = targ.wait;
  258.     else
  259.         self.wait = 0;
  260.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  261.     SUB_CalcMove (targ.origin - self.mins, self.speed, train_wait);
  262. };
  263.  
  264. void() func_train_find =
  265.  
  266. {
  267.     local entity    targ;
  268.  
  269.     targ = find (world, targetname, self.target);
  270.     self.target = targ.target;
  271.     setorigin (self, targ.origin - self.mins);
  272.     if (!self.targetname)
  273.     {    // not triggered, so start immediately
  274.         self.nextthink = self.ltime + 0.1;
  275.         self.think = train_next;
  276.     }
  277. };
  278.  
  279. /*QUAKED func_train (0 .5 .8) ?
  280. Trains are moving platforms that players can ride.
  281. The targets origin specifies the min point of the train at each corner.
  282. The train spawns at the first target it is pointing at.
  283. If the train is the target of a button or trigger, it will not begin moving until activated.
  284. speed    default 100
  285. dmg        default    2
  286. sounds
  287. 1) ratchet metal
  288.  
  289. */
  290. void() func_train =
  291. {    
  292.     if (!self.speed)
  293.         self.speed = 100;
  294.     if (!self.target)
  295.         objerror ("func_train without a target");
  296.     if (!self.dmg)
  297.         self.dmg = 2;
  298.  
  299.     if (self.sounds == 0)
  300.     {
  301.         self.noise = ("misc/null.wav");
  302.         precache_sound ("misc/null.wav");
  303.         self.noise1 = ("misc/null.wav");
  304.         precache_sound ("misc/null.wav");
  305.     }
  306.  
  307.     if (self.sounds == 1)
  308.     {
  309.         self.noise = ("plats/train2.wav");
  310.         precache_sound ("plats/train2.wav");
  311.         self.noise1 = ("plats/train1.wav");
  312.         precache_sound ("plats/train1.wav");
  313.     }
  314.  
  315.     self.cnt = 1;
  316.     self.solid = SOLID_BSP;
  317.     self.movetype = MOVETYPE_PUSH;
  318.     self.blocked = train_blocked;
  319.     self.use = train_use;
  320.     self.classname = "train";
  321.  
  322.     setmodel (self, self.model);
  323.     setsize (self, self.mins , self.maxs);
  324.     setorigin (self, self.origin);
  325.  
  326. // start trains on the second frame, to make sure their targets have had
  327. // a chance to spawn
  328.     self.nextthink = self.ltime + 0.1;
  329.     self.think = func_train_find;
  330. };
  331.  
  332. /*QUAKED misc_teleporttrain (0 .5 .8) (-8 -8 -8) (8 8 8)
  333. This is used for the final bos
  334. */
  335. void() misc_teleporttrain =
  336. {    
  337.     if (!self.speed)
  338.         self.speed = 100;
  339.     if (!self.target)
  340.         objerror ("func_train without a target");
  341.  
  342.     self.cnt = 1;
  343.     self.solid = SOLID_NOT;
  344.     self.movetype = MOVETYPE_PUSH;
  345.     self.blocked = train_blocked;
  346.     self.use = train_use;
  347.     self.avelocity = '100 200 300';
  348.  
  349.     self.noise = ("misc/null.wav");
  350.     precache_sound ("misc/null.wav");
  351.     self.noise1 = ("misc/null.wav");
  352.     precache_sound ("misc/null.wav");
  353.  
  354.     precache_model2 ("progs/teleport.mdl");
  355.     setmodel (self, "progs/teleport.mdl");
  356.     setsize (self, self.mins , self.maxs);
  357.     setorigin (self, self.origin);
  358.  
  359. // start trains on the second frame, to make sure their targets have had
  360. // a chance to spawn
  361.     self.nextthink = self.ltime + 0.1;
  362.     self.think = func_train_find;
  363. };
  364.  
  365.